import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      // 配置巡更模块接口的代理（匹配所有以 /patrol 开头的请求）
      '/patrol': {
        target: 'http://localhost:8009', // 转发到后端 patrol-server 的实际端口 8009
        changeOrigin: true, // 开启跨域模拟
        rewrite: (path) => path.replace(/^\/patrol/, '/patrol') // 保留原路径（无需去掉前缀）
      },
      '/community': {
        target: 'http://localhost:8009', // 转发到后端 patrol-server 的实际端口 8009
        changeOrigin: true, // 开启跨域模拟
        rewrite: (path) => path.replace(/^\/community/, '/community') // 保留原路径（无需去掉前缀）
      },
      // 保留原有的 opencv-server 代理（如果需要）
      '/opencv-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/infrastructure-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/patrol-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/uums-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/property-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/vehicle-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/owner-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/notice-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/repair-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/monitor-server': {
        target: 'http://localhost:9999',
        changeOrigin: true
      },
      '/voice-recognition': {
        target: 'http://localhost:9998',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/voice-recognition/, '/voice-recognition')
      },
      '/sensitive-word': {
        target: 'http://localhost:9998',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/sensitive-word/, '/sensitive-word')
      }
    }
  }
})